import os
import sys
import json
import django
import datetime

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
print(BASE_DIR)
sys.path.extend([BASE_DIR, ])
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "finance_c2c.settings")

django.setup()
from apps.coffee.models import UserCardBag, CardBagRecord


# 卡包管理  卡包过期， 退还卡包
def card_bag_manager():
    now_day = datetime.datetime.today()
    # 券过期
    queryset = UserCardBag.objects.filter(expire_day__lte=now_day)
    queryset.update(
        expired=True
    )
    # 赠出未接收返回
    now_time = datetime.datetime.now()
    end_time = now_time - datetime.timedelta(hours=24)
    record_queryset = CardBagRecord.objects.filter(status=2, create_time__lte=end_time)
    for i in record_queryset:
        i.update_status_3()


if __name__ == '__main__':
    card_bag_manager()
